<?php
	get_header();
?>
<div id="main">
	<div class="inner">
		<?php
			$slides = get_option('slides');
			$slides = json_decode($slides, true);
			if($slides) {
				$carousel_type = get_option('carousel_type', 'carousel-fade');
				echo '<div id="slides" class="carousel slide ' . $carousel_type . '" data-ride="carousel">';

				echo '<ol class="carousel-indicators">';
				for($i=0; $i<count($slides); $i++) {
					$class = $i < 1 ? ' class="active"' : '';
					echo '<li data-target="#slides" data-slide-to="' . $i . '"' . $class . '></li>';
				}
				echo '</ol>';

				echo '<div class="carousel-inner">';
				$class = ' active';
				foreach($slides as $slide) {
					$slide['img'] = esc_url($slide['img']);
					$slide['link'] = esc_url($slide['link']);
					echo '<div class="carousel-item' . $class . '">';
					echo wp_targeted_link_rel('<a href="' . $slide['link'] . '" target="_blank">
							<img src="' . $slide['img'] . '">
						</a>');
					echo '</div>';
					$class = '';
				}
				echo '</div>';

				echo '<a class="carousel-control-prev" href="#slides" data-slide="prev">
						<span class="carousel-control-prev-icon"></span>
					</a>
					<a class="carousel-control-next" href="#slides" data-slide="next">
						<span class="carousel-control-next-icon"></span>
					</a>';
				echo '</div>';
			}
		?>
		<div class="loop">
			<?php get_template_part('loop', ''); ?>
		</div>
	</div>
</div>

<div id="secondary">
	<?php get_sidebar(); ?>
</div>
<?php
	get_footer();
?>